package com.ruoyi.project.order.service;

import com.ruoyi.common.constant.UserConstants;
import com.ruoyi.common.utils.StringUtils;
import com.ruoyi.common.utils.security.ShiroUtils;
import com.ruoyi.project.order.commons.OrderConst;
import com.ruoyi.project.order.domain.Order;
import com.ruoyi.project.order.mapper.OrderMapper;
import com.ruoyi.project.system.post.domain.Post;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

@Service
public class OrderAddServiceImpl implements IOrderAddService {
    @Autowired
    private OrderMapper orderMapper;
    @Override
    public String checkOrderNameUnique(Order order) {
        Long orderId = StringUtils.isNull(order.getOrderId()) ? -1L : order.getOrderId();
        Order info = orderMapper.checkPostNameUnique(order.getOrderName());
        if (StringUtils.isNotNull(info) && info.getOrderId().longValue() != orderId.longValue())
        {
            return OrderConst.ORDER_NAME_NOT_UNIQUE;
        }
        return OrderConst.ORDER_NAME_UNIQUE;
    }

    @Override
    public int insertOrder(Order order) {
        //将当前登录用户的名字赋值到创建人
        order.setCreate_by(ShiroUtils.getLoginName());
        return orderMapper.insertOrder(order);
    }
}
